/**
 * IndexServiceImpl.java
 * Created at 2018-1-3
 * Created by zhanghailin
 * Copyright (C) 2018 BROADTEXT SOFTWARE, All rights reserved.
 */
package com.broadtext.app.index.service.impl;

import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service;

import com.broadtext.app.index.service.IndexService;
import com.broadtext.common.exp.DaoException;
import com.broadtext.common.repository.EntityDao;
import com.broadtext.common.service.impl.EntityServiceImpl;
import com.broadtext.common.utils.DateUtils;
import com.broadtext.rms.monitor.dao.IMonitorWorkBenchDao;
import com.broadtext.rms.monitor.model.TtPackAlert;

/**
 * <p>ClassName: IndexServiceImpl</p>
 * <p>Description: TODO</p>
 * <p>Author: zhanghailin</p>
 * <p>Date: 2018-1-3</p>
 */
@Service("indexService")
public class IndexServiceImpl extends EntityServiceImpl<TtPackAlert> implements IndexService{
    
    /**
     * 注入电池监控Dao
     */
    @Autowired
    @Qualifier("monitorWorkBenchDao")
    private IMonitorWorkBenchDao monitorWorkBenchDao;
    
    @Autowired
    @Qualifier("monitorWorkBenchDao")
    public void setEntityDao(EntityDao<TtPackAlert> entityDao) {
        super.entityDao = entityDao;
    }

    /** (non-Javadoc)
     * <p>Title: getIndexMapData</p>
     * <p>Description: </p>
     * @return
     * @see com.broadtext.app.index.service.IndexService#getIndexMapData()
     */
    @SuppressWarnings("unchecked")
    @Override
    public Map<String, Object> getIndexMapData(Map<String, Object> params) {
        Map<String, Object> map = new HashMap<String, Object>();
        //4、上电分布 
        List<Map<String, String>> powerOnDistributeData;
        try {
            powerOnDistributeData = this.entityDao.findByQuery("com.broadtext.rms.monitor.model.TtPackAlert.getPowerOnDistributeData", params);
            map.put("indexMapData", powerOnDistributeData);
        } catch (DaoException e) {
            e.printStackTrace();
        }
        return map;
    }

    /** (non-Javadoc)
     * <p>Title: getIndexBasicData</p>
     * <p>Description: </p>
     * @return
     * @see com.broadtext.app.index.service.IndexService#getIndexBasicData()
     */
    @Override
    public Map<String, Object> getIndexBasicData(Map<String, Object> params) {
        Map<String, Object> dataMap;
        dataMap = new HashMap<String, Object>();
        String customerId = null;
        if(params.get("cusId")!=null){
            customerId = params.get("cusId").toString();
        }
        // 电池总量
        long total = 0;
        //1、今日报警总数
        long todayAlertNum = 0;
        //2、电池上电总量
        long powerOnNum = 0;
        //电池充电数
        long chargeNum = 0;
        try {
            total = this.monitorWorkBenchDao.findNumByCustomerId("com.broadtext.rms.monitor.model.TtPackAlert.findCustomerPackNum", customerId);
            Map<String, Object> alertParams = new HashMap<String, Object>();
            alertParams.put("todayBeginTime", DateUtils.getDayStartStr(new Date()));
            alertParams.put("customerId", customerId);
            List<Long> todayAlertNumList = this.entityDao.findByProperty("com.broadtext.rms.monitor.model.TtPackAlert.getTotayAlertNumNew", alertParams);
            if(todayAlertNumList!=null&&todayAlertNumList.size()>0&&todayAlertNumList.get(0)!=null){
                todayAlertNum = todayAlertNumList.get(0);
            }
            //todayAlertNum = this.monitorWorkBenchDao.findNumByCustomerId("com.broadtext.rms.monitor.model.TtPackAlert.findTotayAlertNum", customerId);
            powerOnNum = this.monitorWorkBenchDao.findNumByCustomerId("com.broadtext.rms.monitor.model.TtPackAlert.findPowerOnNum", customerId);
            //status : 0 正在充电
            params.put("status", "0");
            params.put("pkId", customerId);
            chargeNum = this.monitorWorkBenchDao.findChargingNumByCustomerId("com.broadtext.rms.monitor.model.TtPackAlert.findPowerFailNum", params);
        } catch (DaoException e) {
            e.printStackTrace();
        }
        dataMap.put("total",total);
        dataMap.put("todayAlertNum", todayAlertNum);
        dataMap.put("powerOnNum", powerOnNum);
        dataMap.put("chargeNum", chargeNum);
        dataMap.put("powerOffNum", total-powerOnNum);
        return dataMap;
    }

    /** (non-Javadoc)
     * <p>Title: getUserInfoByLoginName</p>
     * <p>Description: 根据登录名获取用户信息</p>
     * @param loginName
     * @return
     * @see com.broadtext.app.index.service.IndexService#getUserInfoByLoginName(java.lang.String)
     */
    @Override
    public Map<String, Object> getUserInfoByLoginName(String loginName) {
        Map<String, Object> userMap = new HashMap<String, Object>();
        //userMap = this.entityDao.findByProperty("", propertyValue)
        return null;
    }

}
